
import {searchGradeOrderLimit,addGrade,updateGradeById,deleteGradeById} from "@/api/grade";
import {UPDATE_GRAGE_LIST,UPDATE_GRAGE_DETAIL} from "./types";

export default {
    getGrade({commit},payload){
        return searchGradeOrderLimit(payload).then(res=>{
            var {status,message,list,total,current,maxPage} = res;
            if(status){
                commit(UPDATE_GRAGE_LIST,list)
                commit(UPDATE_GRAGE_DETAIL,{
                    total,
                    current,
                    maxPage
                })
                return message;
            }else{
                throw message;
            }
        })
    },
    addToGrade(content,payload){
        return addGrade(payload).then(res=>{
            var {status,message} = res;
            if(status){
                // commit(ADD_GRAGE_LIST,payload);
                return message;
            }else{
                throw message;
            }
        })
    },
    updateGrade(content,payload){
        return updateGradeById(payload).then(res=>{
            var {status,message} = res;
            if(status){
                // commit(ADD_GRAGE_LIST,payload);
                return message;
            }else{
                throw message;
            }
        })
    },
    deleteGrade(content,payload){
        return deleteGradeById(payload).then(res=>{
            var {status,message} = res;
            if(status){
                // commit(ADD_GRAGE_LIST,payload);
                return message;
            }else{
                throw message;  // 分流
            }
        })
    }



}